﻿namespace HuaWei
{
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Grid;
    using HuaWei.CommClass;
    using HuaWei.DAI;
    using HuaWei.Windows.Forms;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FrmYHXX : Form
    {
        private Bar bar;
        private Bar bar1;
        private BarDockControl barDockControl;
        private BarDockControl barDockControl1;
        private BarDockControl barDockControl2;
        private BarDockControl barDockControl3;
        private BarManager barManager;
        private BindingSource bindingSource;
        private BarLargeButtonItem btnCancel;
        private BarLargeButtonItem btnSave;
        private DataSet dataSet = new DataSet();
        private GridColumn gridColumn1;
        private GridColumn gridColumn2;
        private GridControl gridControl3;
        private GridView gridView1;
        private IContainer icontainer = null;
        private RepositoryItemTextEdit repositoryItemTextEdit1;

        public FrmYHXX()
        {
            this.InitializeComponent();
        }

        private void btnCancel_ItemClick(object sender, ItemClickEventArgs e)
        {
            base.Close();
        }

        private void btnSave_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.method1();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.icontainer != null))
            {
                this.icontainer.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FrmYHXX_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.bindingSource.EndEdit();
            if (this.dataSet.HasChanges() && (MsgBox.ShowQuestion("数据已被修改\n\n\n确定->保存退出\n取消->不保存退出！") == System.Windows.Forms.DialogResult.OK))
            {
                this.method1();
            }
        }

        private void FrmYHXX_Load(object sender, EventArgs e)
        {
            this.method();
        }

        private void InitializeComponent()
        {
            this.icontainer = new Container();
            this.bar = new Bar();
            this.barManager = new BarManager(this.icontainer);
            this.bar1 = new Bar();
            this.btnSave = new BarLargeButtonItem();
            this.btnCancel = new BarLargeButtonItem();
            this.barDockControl = new BarDockControl();
            this.barDockControl1 = new BarDockControl();
            this.barDockControl2 = new BarDockControl();
            this.barDockControl3 = new BarDockControl();
            this.gridControl3 = new GridControl();
            this.bindingSource = new BindingSource(this.icontainer);
            this.gridView1 = new GridView();
            this.gridColumn1 = new GridColumn();
            this.gridColumn2 = new GridColumn();
            this.repositoryItemTextEdit1 = new RepositoryItemTextEdit();
            this.barManager.BeginInit();
            this.gridControl3.BeginInit();
            ((ISupportInitialize) this.bindingSource).BeginInit();
            this.gridView1.BeginInit();
            this.repositoryItemTextEdit1.BeginInit();
            base.SuspendLayout();
            this.bar.BarName = "Main menu";
            this.bar.DockCol = 0;
            this.bar.DockRow = 0;
            this.bar.DockStyle = BarDockStyle.Top;
            this.bar.FloatLocation = new Point(330, 0x91);
            this.bar.FloatSize = new Size(0x14b, 0x35);
            this.bar.OptionsBar.AllowQuickCustomization = false;
            this.bar.OptionsBar.MultiLine = true;
            this.bar.OptionsBar.UseWholeRow = true;
            this.bar.Text = "Main menu";
            this.barManager.Bars.AddRange(new Bar[] { this.bar1 });
            this.barManager.DockControls.Add(this.barDockControl);
            this.barManager.DockControls.Add(this.barDockControl1);
            this.barManager.DockControls.Add(this.barDockControl2);
            this.barManager.DockControls.Add(this.barDockControl3);
            this.barManager.Form = this;
            this.barManager.Items.AddRange(new BarItem[] { this.btnCancel, this.btnSave });
            this.barManager.MainMenu = this.bar1;
            this.barManager.MaxItemId = 3;
            this.bar1.BarName = "Main menu";
            this.bar1.DockCol = 0;
            this.bar1.DockRow = 0;
            this.bar1.DockStyle = BarDockStyle.Top;
            this.bar1.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.btnSave), new LinkPersistInfo(this.btnCancel) });
            this.bar1.OptionsBar.MultiLine = true;
            this.bar1.OptionsBar.UseWholeRow = true;
            this.bar1.Text = "Main menu";
            this.btnSave.Caption = "确定";
            this.btnSave.Id = 2;
            this.btnSave.Name = "btnSave";
            this.btnSave.ItemClick += new ItemClickEventHandler(this.btnSave_ItemClick);
            this.btnCancel.Caption = "取消";
            this.btnCancel.Id = 1;
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.ItemClick += new ItemClickEventHandler(this.btnCancel_ItemClick);
            this.barDockControl.Dock = DockStyle.Top;
            this.barDockControl.Location = new Point(0, 0);
            this.barDockControl.Size = new Size(0x182, 0x18);
            this.barDockControl1.Dock = DockStyle.Bottom;
            this.barDockControl1.Location = new Point(0, 0x10d);
            this.barDockControl1.Size = new Size(0x182, 0);
            this.barDockControl2.Dock = DockStyle.Left;
            this.barDockControl2.Location = new Point(0, 0x18);
            this.barDockControl2.Size = new Size(0, 0xf5);
            this.barDockControl3.Dock = DockStyle.Right;
            this.barDockControl3.Location = new Point(0x182, 0x18);
            this.barDockControl3.Size = new Size(0, 0xf5);
            this.gridControl3.DataMember = null;
            this.gridControl3.DataSource = this.bindingSource;
            this.gridControl3.Dock = DockStyle.Fill;
            this.gridControl3.EmbeddedNavigator.Buttons.CancelEdit.Visible = false;
            this.gridControl3.EmbeddedNavigator.Buttons.Edit.Visible = false;
            this.gridControl3.EmbeddedNavigator.Buttons.EndEdit.Visible = false;
            this.gridControl3.Location = new Point(0, 0x18);
            this.gridControl3.MainView = this.gridView1;
            this.gridControl3.Name = "gridControl3";
            this.gridControl3.RepositoryItems.AddRange(new RepositoryItem[] { this.repositoryItemTextEdit1 });
            this.gridControl3.Size = new Size(0x182, 0xf5);
            this.gridControl3.TabIndex = 4;
            this.gridControl3.UseEmbeddedNavigator = true;
            this.gridControl3.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { this.gridView1 });
            this.gridView1.Columns.AddRange(new GridColumn[] { this.gridColumn1, this.gridColumn2 });
            this.gridView1.GridControl = this.gridControl3;
            this.gridView1.Name = "gridView1";
            this.gridView1.OptionsCustomization.AllowFilter = false;
            this.gridView1.OptionsCustomization.AllowSort = false;
            this.gridView1.OptionsView.ShowGroupPanel = false;
            this.gridColumn1.Caption = "用户名";
            this.gridColumn1.FieldName = "YHMC";
            this.gridColumn1.Name = "gridColumn1";
            this.gridColumn1.Visible = true;
            this.gridColumn1.VisibleIndex = 0;
            this.gridColumn1.Width = 0x93;
            this.gridColumn2.Caption = "密码";
            this.gridColumn2.ColumnEdit = this.repositoryItemTextEdit1;
            this.gridColumn2.FieldName = "YHMM";
            this.gridColumn2.Name = "gridColumn2";
            this.gridColumn2.Visible = true;
            this.gridColumn2.VisibleIndex = 1;
            this.gridColumn2.Width = 0xda;
            this.repositoryItemTextEdit1.AutoHeight = false;
            this.repositoryItemTextEdit1.Name = "repositoryItemTextEdit1";
            this.repositoryItemTextEdit1.PasswordChar = '*';
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            base.ClientSize = new Size(0x182, 0x10d);
            base.Controls.Add(this.gridControl3);
            base.Controls.Add(this.barDockControl2);
            base.Controls.Add(this.barDockControl3);
            base.Controls.Add(this.barDockControl1);
            base.Controls.Add(this.barDockControl);
            base.Name = "FrmYHXX";
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "用户信息";
            base.FormClosing += new FormClosingEventHandler(this.FrmYHXX_FormClosing);
            base.Load += new EventHandler(this.FrmYHXX_Load);
            this.barManager.EndInit();
            this.gridControl3.EndInit();
            ((ISupportInitialize) this.bindingSource).EndInit();
            this.gridView1.EndInit();
            this.repositoryItemTextEdit1.EndInit();
            base.ResumeLayout(false);
        }

        private void method()
        {
            IDataAccess idataAccess = DBHelp.IniIDA();
            string str = "select * from YHXX where jgid='#id#'".Replace("#id#", GParams.LoginId);
            Class39.smethod4(idataAccess, this.dataSet, str, "YHXX", true);
            DataTable dt = this.dataSet.Tables["YHXX"];
            dt.TableNewRow += new DataTableNewRowEventHandler(FrmYHXX.TableNewRow);
            if (dt.Rows.Count.Equals(0))
            {
                DataRow row = DHelp.AddRow(dt);
                row["YHMC"] = "admin";
                row["YHMM"] = "888888";
                row.EndEdit();
            }
            this.bindingSource.DataSource = dt;
            idataAccess.CloseDatabase();
        }

        private void method1()
        {
            this.bindingSource.EndEdit();
            if (this.dataSet.HasChanges())
            {
                IDataAccess access = DBHelp.IniIDA();
                access.OpenDatabase();
                access.BeginTrans();
                try
                {
                    access.Update(this.dataSet, true);
                    access.Commit();
                    MsgBox.ShowMsg("数据已成功保存！");
                }
                finally
                {
                    access.CloseDatabase();
                }
            }
        }

        public static void TableNewRow(object sender, DataTableNewRowEventArgs e)
        {
            DataColumnCollection columns = e.Row.Table.Columns;
            e.Row["id"] = Guid.NewGuid();
            e.Row["JGID"] = GParams.LoginId;
        }
    }
}

